﻿Imports System.Data.SqlClient

Public Class frmStaffStatus

    Private Sub frmStaffStatus_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FillGridStatus()
        Me.WindowState = FormWindowState.Maximized
    End Sub

    Sub FillGridStatus()
        Try
            Me.Cursor = Cursors.WaitCursor
            Dim cmd As New SqlCommand("select EmpNo,FullNameEn, Branch, Position, Nationality, dbo.GetEmpStatus2(EmpNo,GETDATE()) as Active from StaffProfiles ", cnn) 'the old
            Dim Reader As SqlDataReader

            Me.GridStatus.Rows.Clear()

            cnn.Open()
            Reader = cmd.ExecuteReader
            While Reader.Read
                Me.GridStatus.Rows.Add(New String() {Reader.Item("EmpNo"), Reader.Item("FullNameEn"), Reader.Item("Branch"), _
                                                     Reader.Item("Position"), Reader.Item("Nationality"), Reader.Item("Active")})
            End While
            cnn.Close()

            'Check status color
            For Each row As DataGridViewRow In Me.GridStatus.Rows
                If row.Cells(5).Value = "On Leave" Then
                    row.DefaultCellStyle.BackColor = Color.LightCoral
                ElseIf row.Cells(5).Value = "Absent" Then
                    row.DefaultCellStyle.BackColor = Color.LightBlue
                ElseIf row.Cells(5).Value = "Active" Then
                    row.DefaultCellStyle.BackColor = Color.White
                End If
            Next

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            MsgBox(ex.ToString)
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
        End Try
    End Sub

    Private Sub GridStatus_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GridStatus.CellContentClick

    End Sub

End Class